package com.gang.ssm.bos.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gang.ssm.bos.system.bean.Menu;
import com.gang.ssm.bos.system.mapper.MenuMapper;
import com.gang.ssm.bos.system.service.MenuService;



@Service
public class MenuServiceImpl implements MenuService {
	
	@Autowired
	private MenuMapper menuMapper;

	@Override
	public List<Menu> getByParentId(Integer parentId) {
		return menuMapper.getByParentId(parentId);
	}

	@Override
	public List<Integer> findMenuIdsByRoleId(Integer roleId) {
		return menuMapper.findMenuIdsByRoleId(roleId);
	}

	@Override
	public List<Menu> findAll() {
		return menuMapper.findAll();
	}

	@Override
	public void saveOrUpdate(Menu menu) {
		
		if(menu.getParentId() == null) {
			menu.setParentId(0);
		}
		
		if(menu.getId() == null) {
			menuMapper.add(menu);
		} else {
			menuMapper.update(menu);
		}
	}

	@Override
	public void deleteById(Integer id) {
		
		menuMapper.deleteRoleMenuByMenuId(id);
		menuMapper.deleteByMenuId(id);
	}

	@Override
	public List<Menu> findForTreeTable(int parentId) {
		return menuMapper.findForTreeTable(parentId);
	}

	@Override
	public List<Menu> find(Menu menu) {
		return menuMapper.find(menu);
	}

	@Override
	public Menu getById(Integer id) {
		return menuMapper.getById(id);
	}

	@Override
	public List<String> findUrlByRoleId(Integer roleId) {
		
		return menuMapper.findUrlByRoleId(roleId);
	}
}
